home *** CD-ROM | disk | FTP | other *** search
/ Die Ultimative Software-P…i Collection 1996 & 1997 / Die Ultimative Software-Pakete CD-ROM fur Atari Collection 1996 & 1997.iso / p / pofo / utility / acdpw2 / password.c next >
Encoding:
C/C++ Source or Header  |  1991-08-21  |  2.6 KB  |  110 lines

  1.  /***************************************************************
  2.  * password.c -- simple password protection for the portfolio   *
  3.  *                                                              *
  4.  * Author : Alan Davis CIS:72317,3661                           *
  5.  *                                                              *
  6.  * Implementation : TurboC v2.0                                 *
  7.  *                                                              *
  8.  * edits                                                        *
  9.  * 1.1  added c_break protection                                *
  10.  *                                                              * 
  11.  *    This program is hereby dedicated to the PUBLIC DOMAIN     *
  12.  ***************************************************************/
  13.  
  14.  
  15. #include <stdio.h>
  16. #include <conio.h>
  17. #include <string.h>
  18. #include <setjmp.h>
  19. #include <dos.h>
  20.  
  21. #define PWLEN 10
  22. #define BS    8
  23. #define CR    13
  24. #define SP    32
  25.  
  26. jmp_buf restart;
  27. int c_break(void);
  28.  
  29. int i, c;            /* counter       */
  30. char *pwd,            /* user password */
  31. *text[5],            /* usage message */
  32. *ind,                /* buffer        */
  33.  prompt[] = "Enter Password : ";
  34.  
  35.  
  36. main(argc, argv)
  37.     int argc;
  38.     char **argv;
  39. {
  40.  
  41.     ctrlbrk(c_break); /* set new control-break handler */
  42.  
  43.     text[0] = "passwd V1.1\n";
  44.     text[1] = "Alan Davis, Sept 1990\n\n";
  45.     text[2] = "Usage : passwd phlugg\n";
  46.     text[3] = "Where phlugg is the password\n";
  47.     text[4] = "Password is limited to 10 chars.\n";
  48.     i = 0;
  49.  
  50.     /* check for no password on command line */
  51.     if (argc <= 1)
  52.     {
  53. usage:                /* print usage message */
  54.     for (c = 0; c <= 4; c++)
  55.     {
  56.         ind = text[c];
  57.         for (i = 0; ind[i] != NULL; i++)
  58.         putchar(ind[i]);
  59.     }
  60.     exit(1);
  61.     }
  62.     else            /* make sure password isn't too long */
  63.     {
  64.     for (i = 0; argv[1][i] != NULL; i++);
  65.     if (i > PWLEN)
  66.         goto usage;        /* yuck!, but it saves code */
  67.     }
  68.  
  69.     pwd = (char *) malloc(11 * sizeof(char));
  70.  
  71.     setjmp(restart); /* this is where we come to on ctrl-c */
  72.  
  73.     /* prompt for the password */
  74.     while (1)
  75.     {
  76.  
  77.     for (i = 0; prompt[i] != NULL; i++)
  78.         putchar(prompt[i]);
  79.     i = c = 0;
  80.  
  81.     /* and get it, don't let it get too long */
  82.     while ((c = getch()) != CR && i < PWLEN)
  83.     {
  84.         putchar('*');
  85.         pwd[i++] = c;
  86.  
  87.     }
  88.     pwd[i] = NULL;
  89.  
  90.     /* check it */
  91.     if (!stricmp(pwd, argv[1]))
  92.     {
  93.         putchar(CR);
  94.         exit(1);        /* if it's ok */
  95.     }
  96.     for (c = i; c != 0; c--)/* else clear the line and reprompt */
  97.         putchar(BS);
  98.     for (c = i; c != 0; c--)
  99.         putchar(SP);
  100.  
  101.     putchar(CR);
  102.     }
  103. }
  104.  
  105. int c_break(void)
  106. {
  107.     longjmp(restart,1);
  108. }
  109.  
  110.